package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.api.db.ConclusionApi;
import com.tanhua.dubbo.api.mapper.ConclusionMapper;
import com.tanhua.model.db.Conclusion;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Classname ConclusionApiImpl
 * @Description
 * @Version 1.0.0
 * @Date 2021/12/28 11:08
 * @Created by zk
 */
@DubboService
public class ConclusionApiImpl implements ConclusionApi {

    @Autowired
    private ConclusionMapper conclusionMapper;


    /**
     * 根据类型查找相同的结论
     * @param maxDimension
     * @return
     */
    @Override
    public List<Long> findByType(String maxDimension, Long userId) {
        QueryWrapper<Conclusion> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dimension_type", maxDimension);
        queryWrapper.ne("user_id",userId);
        List<Conclusion> conclusions = conclusionMapper.selectList(queryWrapper);
        return conclusions.stream().map(Conclusion::getUserId).collect(Collectors.toList());
    }

    /**
     * 存表
     * @param conclusion
     */
    @Override
    public void save(Conclusion conclusion) {
        conclusionMapper.insert(conclusion);
    }
}